const Model = require('./Model')
const crypto = require('crypto')
class Test extends Model {
    constructor() {
        super()
        let M = this.structure()    // 结构
        this.init(M)                // 一些插件 方法
        return this.mongoose.model('Test', M)   // 实例化
    }
    structure() {
        return new this.Schame({
            username: {
                type: String,
                required: true,
            },
            password: {
                type: String,
                required: true,
            },
            display_name: {
                type: String,
                default: 'User',
            }
        })
    }
    init(model) {
        // 写入加密
        model.path('password').set(password => crypto.createHash('md5').update('password').digest('hex'))

        return model
    }
}

module.exports = new Test()